#pragma once
#include "process.h"

template<class T>
class ThreadImpl
{
	typedef void (T::*pfnFunc_t)(LPVOID);
	typedef struct tagThreadInfo
	{
		T *pThis;
		pfnFunc_t pFunc;
		LPVOID pData;
	}THREADINFO;
protected:
	HANDLE CreateThread(pfnFunc_t pFunc, T* pThis, LPVOID pData)
	{
		static THREADINFO info = {0};
		info.pThis = pThis;
		info.pFunc = pFunc;
		info.pData = pData;
		return (HANDLE)_beginthread(ThreadFunc, 0, (LPVOID)&info);
	}

	static void ThreadFunc(LPVOID pData)
	{
		THREADINFO *pInfo = (THREADINFO *)pData;
		(pInfo->pThis->*pInfo->pFunc)(pInfo->pData);
	}
};